/*_____________________________________________________________________________
||
|| swip.h
||
|| Jinfeng Zhuang, 2024.W17
||
|| like API: ip_command(param1, param2)
||           uart1_send(buffer, size)
||           uart2_send(buffer, size)
||
|| The parameter 'ip' is used to distinguish UART1, UART2,... with same handler
||______________________________________________________________________________
*/

#ifndef SWIP_H
#define SWIP_H

typedef unsigned int U32;

enum swip_ip
{
    /* SOC */
    SWIP_SOC_CORE,
    SWIP_SOC_CLOCK,
    SWIP_SOC_POWER,
    SWIP_SOC_BACKUP,
    SWIP_SOC_IOMUX,
    SWIP_SOC_INTCTRL,
    SWIP_SOC_SYSTICK,

    SWIP_SOC_WDG,
    SWIP_SOC_DMA1,
    SWIP_SOC_DMA2,
    SWIP_SOC_SRAM,
    SWIP_SOC_CRC,
    SWIP_SOC_FLASH,   // FLITF
    SWIP_SOC_TIMER1,
    SWIP_SOC_TIMER2,
    SWIP_SOC_TIMER3,
    SWIP_SOC_TIMER4,
    SWIP_SOC_TIMER5,
    SWIP_SOC_TIMER6,
    SWIP_SOC_TIMER7,
    SWIP_SOC_TIMER8,
    SWIP_SOC_TIMER9,
    SWIP_SOC_TIMER10,
    SWIP_SOC_TIMER11,
    SWIP_SOC_TIMER12,
    SWIP_SOC_TIMER13,
    SWIP_SOC_TIMER14,
    SWIP_SOC_GPIO,

    SWIP_SOC_ADC1,
    SWIP_SOC_ADC2,
    SWIP_SOC_ADC3,
    SWIP_SOC_DAC1,

    SWIP_SOC_UART1,
    SWIP_SOC_UART2,
    SWIP_SOC_UART3,
    SWIP_SOC_UART4,
    SWIP_SOC_UART5,
    SWIP_SOC_UART6,
    SWIP_SOC_I2C1,
    SWIP_SOC_I2C2,
    SWIP_SOC_I2C3,
    SWIP_SOC_SPI1,
    SWIP_SOC_SPI2,
    SWIP_SOC_SPI3,
    SWIP_SOC_CAN1,
    SWIP_SOC_CAN2,
    SWIP_SOC_SDIO,
    SWIP_SOC_FSMC,   // Flexible Static Memory Controller
    SWIP_SOC_USB,
    SWIP_SOC_ENET,

    /* Software timer: drive period tasks */
    SWIP_SOFTWARE_TIMER,

    SWIP_TEST,
    SWIP_CMD_DELAY,

    /* Devices: Handle Hardware related features, such as delay... */
    SWIP_DEV_LTC68xx,
    SWIP_DEV_PCS,
    SWIP_DEV_EEPROM,
    SWIP_DEV_RTC,
    SWIP_DEV_ADX111,
    SWIP_DEV_TEMP,
    SWIP_DEV_BALANCE,
    SWIP_DEV_SNMP,
    SWIP_DEV_LCD,
    SWIP_DEV_PC,
    SWIP_DEV_MPU6050,
    SWIP_DEV_NRF24L01,

    /* Policy: Periodly */
    SWIP_TASK_BATT,
    SWIP_TASK_RELAY,
    SWIP_TASK_SOC,
    SWIP_TASK_SOH,
    SWIP_TASK_OVP,
    SWIP_TASK_FAN,
    SWIP_TASK_SYNC_SLAVE,
    SWIP_TASK_SYNC_MASTER,
    SWIP_TASK_LIMIT_CURR,

    SWIP_ALGO_PID,

    SWIP_MAX,
};

enum swip_command
{
    SWCMD_MEMMAP,
    SWCMD_CONNECT,
    SWCMD_CONFIG,
    SWCMD_CLOCK_DRIVE,   // clock
    SWCMD_CLOCK_GET,
    SWCMD_CLOCK_SET,
    SWCMD_ENABLE,
    SWCMD_DISABLE,
    SWCMD_TRANSFER_TYPE,   // BLOCK, INT, DMA
    SWCMD_WRITE,
    SWCMD_READ,
    SWCMD_SEND,
    SWCMD_RECV,
    SWCMD_SELFTEST,
    SWCMD_USER,
};

enum swip_param
{
    SWPARAM_PLL_SRC,
    SWPARAM_PLL_HSE,
    SWPARAM_PLL_HSI,
    SWPARAM_PLL_M,
    SWPARAM_PLL_N,
    SWPARAM_PLL_P,
    SWPARAM_PLL_I2S_N,
    SWPARAM_PLL_I2S_R,
    SWPARAM_AHB_PRESCALER,
    SWPARAM_APB1_PRESCALER,
    SWPARAM_APB2_PRESCALER,
    SWPARAM_PA0  = (0 << 16 | 0),
    SWPARAM_PC8  = (2 << 16 | 8),
    SWPARAM_PC9  = (2 << 16 | 9),
    SWPARAM_PC10 = (2 << 16 | 10),
    SWPARAM_PC11 = (2 << 16 | 11),
    SWPARAM_PC12 = (2 << 16 | 12),
    SWPARAM_PD2  = (3 << 16 | 2),
};

U32 swip_call(U32 ip, U32 cmd, U32 param1, U32 param2);

#endif
